package com.project.poetry.common.config;

import com.project.poetry.common.interceptor.PoetryInterceptor;
import org.springframework.stereotype.Component;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

/**
 * 配置信息
 * @author mengxj
 */
@Component
public class InterceptorConfig implements WebMvcConfigurer {

    @Resource
    private PoetryInterceptor poetryInterceptor;

    @Resource
    private ParamResolvers paramResolvers;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(poetryInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/page/index")
                .excludePathPatterns("/page/reg")
                .excludePathPatterns("/page/common/login")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**")
                .excludePathPatterns("/favicon.ico")
                .excludePathPatterns("/page/question/**")
                .excludePathPatterns("/question/**");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(paramResolvers);
    }
}
